#!/usr/bin/env python
# -*- coding: utf-8 -*-

import wx
import time,datetime
import EntryValid
import sys
import wx.lib.masked as masked
import pymssql
import threading

def DBConnection():
    conn=pymssql.connect(host='127.0.0.1',user='sa',password='',database='testdb',charset='gbk' )
    cur=conn.cursor()
    return conn,cur

class EditDialog(wx.Dialog):
    def __init__(self,parent,id,title,InitValue):
        """
        __init__(self, Window parent, int id=-1, String title=EmptyString, 
        Point pos=DefaultPosition, Size size=DefaultSize, 
        long style=DEFAULT_DIALOG_STYLE, String name=DialogNameStr) -> Dialog
        """
        self.InitValue=InitValue
        wx.Dialog.__init__(self,parent,id,title,style=wx.DEFAULT_DIALOG_STYLE)
        
        self.sizer_2_staticbox = wx.StaticBox(self, -1, u"订单信息：")
        self.sizer_5_staticbox = wx.StaticBox(self, -1, u"异常信息：")
        self.sizer_7_staticbox = wx.StaticBox(self, -1, u"其他信息：")
        self.sizer_6_staticbox = wx.StaticBox(self, -1, u"客户信息：")
        self.khdm_label = wx.StaticText(self, 401, u"客户代码：")
        self.khdm_ctrl = wx.TextCtrl(self, 402, "",validator=EntryValid.Non_Empty())
        self.khmc_label = wx.StaticText(self, 403, u"客户名称：")
        self.khmc_ctrl = wx.TextCtrl(self, 404, "")
        self.yewy_label = wx.StaticText(self, 405, u"业务员代码：")
        self.yewy_ctrl = wx.TextCtrl(self, 406, "")
        self.bjrq_label = wx.StaticText(self, 407, u"报价日期：")
        self.bjrq_datectrl = wx.DatePickerCtrl(self, 408)
        self.bjyx_label = wx.StaticText(self, 409, u"报价有效期：")
        self.bjyx_datectrl = wx.DatePickerCtrl(self, 410)
        self.ddsl_label = wx.StaticText(self, 411, u"订单数量：")
        self.ddsl_ctrl = wx.TextCtrl(self, 412, "0",validator=EntryValid.OnIntValidator())
        self.ddjs_label = wx.StaticText(self, 413, u"订单接收时间：")
        self.ddjs_datectrl = wx.DatePickerCtrl(self, 414)
        self.ddjs_timectrl=masked.TimeCtrl( self, -1,'12:00',fmt24hr=True,display_seconds = False)
        #self.ddjs_ctrl = wx.TextCtrl(self, 415,self.local_time,validator=EntryValid.TimeValidator())
        self.ddff_label = wx.StaticText(self, 416, u"订单分发时间：")
        self.ddff_datectrl = wx.DatePickerCtrl(self, 417)
        self.ddff_timectrl=masked.TimeCtrl( self, -1,'12:00',fmt24hr=True,display_seconds = False)
        #self.ddff_ctrl = wx.TextCtrl(self, 418,self.local_time,validator=EntryValid.TimeValidator())
        self.hth_label = wx.StaticText(self, 419, u"合同号：")
        self.hth_ctrl = wx.TextCtrl(self, 420, "",validator=EntryValid.Non_Empty())
        self.ycsl_label = wx.StaticText(self, 421, u"异常数量：")
        self.ycsl_ctrl = wx.TextCtrl(self, 422, "0",validator=EntryValid.OnIntValidator())
        self.ycyy_label = wx.StaticText(self, 423, u"异常原因：")
        self.ycyy_ctrl = wx.TextCtrl(self, 424, "")
        self.czsj_label = wx.StaticText(self, 425, u"传真时间：")
        self.czsj_datectrl = wx.DatePickerCtrl(self, 426)
        self.czsj_timectrl=masked.TimeCtrl( self, -1,'12:00',fmt24hr=True,display_seconds = False)
        #self.czsj_ctrl = wx.TextCtrl(self, 427,self.local_time,validator=EntryValid.TimeValidator())
        self.xgsj_label = wx.StaticText(self, 428, u"修改时间：")
        self.xgsj_datectrl = wx.DatePickerCtrl(self, 429)
        self.xgsj_timectrl=masked.TimeCtrl( self, -1,'12:00',fmt24hr=True,display_seconds = False)
        #self.xgsj_ctrl = wx.TextCtrl(self, 430,self.local_time,validator=EntryValid.TimeValidator())
        self.hcsj_label = wx.StaticText(self, 431, u"回传时间：")
        self.hcsj_datectrl = wx.DatePickerCtrl(self, 432)
        self.hcsj_timectrl=masked.TimeCtrl( self, -1,'12:00',fmt24hr=True,display_seconds = False)
        #self.hcsj_ctrl = wx.TextCtrl(self, 433,self.local_time,validator=EntryValid.TimeValidator())
        self.xgyy_label = wx.StaticText(self, 434, u"合同修改原因：")
        self.xgyy_ctrl = wx.TextCtrl(self, 435, "")
        self.half_label = wx.StaticText(self, 436, u"0.5小时合同回传情况：")
        self.half_ctrl = wx.TextCtrl(self, 437, "")
        self.two_label = wx.StaticText(self, 438, u"2小时候合同跟进情况：")
        self.two_ctrl = wx.TextCtrl(self, 439, "")
        self.day_label = wx.StaticText(self, 440, u"1工作日合同跟进情况：")
        self.day_ctrl = wx.TextCtrl(self, 441, "")
        self.tcry_label = wx.StaticText(self, 442, u"投产人员：")
        self.tcry_ctrl = wx.TextCtrl(self, 443, "")
        self.tcff_label = wx.StaticText(self, 444, u"投产单发放时间：")
        self.tcff_datectrl = wx.DatePickerCtrl(self, 445)
        self.tcff_timectrl=masked.TimeCtrl( self, -1,'12:00',fmt24hr=True,display_seconds = False)
        #self.tcff_ctrl = wx.TextCtrl(self, 446,self.local_time,validator=EntryValid.TimeValidator())
        self.noback_label = wx.StaticText(self, 447, u"未回传合同原因：")
        self.noback_ctrl = wx.TextCtrl(self, 448, "")
        self.zzzq_label = wx.StaticText(self, 449, u"合同制作周期：")
        self.zzzq_ctrl = wx.TextCtrl(self, 450, u"0天0小时0分",style=wx.TE_READONLY,validator=EntryValid.TimeLogic())
        self.tczq_label = wx.StaticText(self, 451, u"合同投产周期：")
        self.tczq_ctrl = wx.TextCtrl(self, 452, u"0天0小时0分",style=wx.TE_READONLY,validator=EntryValid.TimeLogic())
        self.bz_label = wx.StaticText(self, 453, u"备注：")
        self.bz_ctrl = wx.TextCtrl(self, 454, "", style=wx.TE_MULTILINE)
        self.save_button = wx.Button(self, wx.ID_OK, "Save")
        self.cancel_button = wx.Button(self, wx.ID_CANCEL, "Cancal")
        
        self.__set_properties()
        self.__do_layout()
        
        #计算制作周期和投产周期---------------------------------------------------------------
        self.ddjs_datectrl.Bind(wx.EVT_DATE_CHANGED,self._Setzzzq)
        self.ddjs_timectrl.Bind(wx.EVT_TEXT,self._Setzzzq)
        self.czsj_datectrl.Bind(wx.EVT_DATE_CHANGED,self._Setzzzq)
        self.czsj_timectrl.Bind(wx.EVT_TEXT,self._Setzzzq)
        
        self.tcff_datectrl.Bind(wx.EVT_DATE_CHANGED,self._Settczq)
        self.tcff_timectrl.Bind(wx.EVT_TEXT,self._Settczq)
        self.hcsj_datectrl.Bind(wx.EVT_DATE_CHANGED,self._Settczq)
        self.hcsj_timectrl.Bind(wx.EVT_TEXT,self._Settczq)
        #--------------------------------------------------------------------------------------
        
        self.khdm_ctrl.Bind(wx.EVT_KILL_FOCUS,self._Query2Values)

    def _Query2Values(self,evt):  #无修改和无内容不查询
        if self.khdm_ctrl.GetValue()==self.InitValue or self.khdm_ctrl.GetValue()=="":
            self.InitValue=""  #重置查询条件
        else:
            
            query2=QueryKHXS(self.khdm_ctrl.GetValue(),self)
            print query2.isDaemon()
            query2.start()
        
    
    def _Setzzzq(self,evt):
        D1=self.HBTime(self.czsj_datectrl.GetValue(),self.czsj_timectrl.GetValue())
        D2=self.HBTime(self.ddjs_datectrl.GetValue(),self.ddjs_timectrl.GetValue())
        if D1<D2:
            self.zzzq_ctrl.SetValue("")
        else:
            zq=D1-D2
            hour=divmod(zq.seconds,3600)[0]
            mint=divmod(zq.seconds,3600)[1]/60
            self.zzzq_ctrl.SetValue(u"%d天%d小时%d分" %(zq.days,hour,mint))
        evt.Skip()
            
                
    def _Settczq(self,evt):
        D1=self.HBTime(self.tcff_datectrl.GetValue(),self.tcff_timectrl.GetValue())
        D2=self.HBTime(self.hcsj_datectrl.GetValue(),self.hcsj_timectrl.GetValue())
        if D1<D2:
            self.tczq_ctrl.SetValue("")
        else:
            zq=D1-D2
            hour=divmod(zq.seconds,3600)[0]
            mint=divmod(zq.seconds,3600)[1]/60
            self.tczq_ctrl.SetValue(u"%d天%d小时%d分" %(zq.days,hour,mint))
        evt.Skip()
    

    # 时间格式的转换---------------------------------------------------
    def _pydate2wxdate(self,date):
        assert isinstance(date, (datetime.datetime, datetime.date))
        tt = date.timetuple()
        dmy = (tt[2], tt[1]-1, tt[0])
        return wx.DateTimeFromDMY(*dmy)
    
    def _wxdate2pydate(self,date):
        assert isinstance(date, wx.DateTime)
        if date.IsValid():
            ymd = map(int, date.FormatISODate().split('-'))
            return datetime.date(*ymd)
        else:
            return None    #此程序只用了wxdata 转 pydata
    #---------------------------------------------------------------------
    
    #合并DatePickerCtrl和TimeCtrl，产生一个datetime.datetime(pydate)时间格式
    def HBTime(self,Edate,Etime):
        pydate=self._wxdate2pydate(Edate)
        pytime=Etime.split(":")
        pyhour=int(pytime[0])
        pymin=int(pytime[1])
        return datetime.datetime(pydate.year,pydate.month,pydate.day,pyhour,pymin)
            

            

    def __set_properties(self):
        self.SetTitle(u"修改一条记录")
        self.khdm_ctrl.SetMinSize((100, 24))
        self.khmc_ctrl.SetMinSize((100, 24))
        #self.khmc_ctrl.SetBackgroundColour(wx.Colour(192, 192, 192))
        #self.yewy_ctrl.SetBackgroundColour(wx.Colour(192, 192, 192))
        self.bjrq_datectrl.SetMinSize((120, 26))
        self.bjyx_datectrl.SetMinSize((120, 26))
        self.ddjs_datectrl.SetMinSize((120, 26))
        self.ddjs_timectrl.SetMinSize((40, 24))
        self.ddff_datectrl.SetMinSize((120, 26))
        self.ddff_timectrl.SetMinSize((40, 24))
        self.ycyy_ctrl.SetMinSize((613, 24))
        self.czsj_datectrl.SetMinSize((120, 26))
        self.czsj_timectrl.SetMinSize((40, 24))
        self.xgsj_datectrl.SetMinSize((120, 26))
        self.xgsj_timectrl.SetMinSize((40, 24))
        self.hcsj_datectrl.SetMinSize((120, 26))
        self.hcsj_timectrl.SetMinSize((43, 24))
        self.xgyy_ctrl.SetMinSize((589, 35))
        self.half_ctrl.SetMinSize((547, 24))
        self.two_ctrl.SetMinSize((546, 24))
        self.day_ctrl.SetMinSize((546, 24))
        self.tcff_datectrl.SetMinSize((120, 26))
        self.tcff_timectrl.SetMinSize((40, 24))
        self.noback_ctrl.SetMinSize((574, 24))
        self.bz_ctrl.SetMinSize((639, 35))
        # end wxGlade

    def __do_layout(self):
        sizer_1 = wx.BoxSizer(wx.VERTICAL)
        sizer_3 = wx.BoxSizer(wx.HORIZONTAL)
        grid_sizer_2 = wx.GridSizer(1, 2, 0, 10)
        sizer_7 = wx.StaticBoxSizer(self.sizer_7_staticbox, wx.HORIZONTAL)
        grid_sizer_46 = wx.FlexGridSizer(4, 1, 3, 0)
        grid_sizer_54 = wx.FlexGridSizer(1, 2, 0, 0)
        grid_sizer_51 = wx.GridSizer(1, 2, 0, 20)
        grid_sizer_53 = wx.FlexGridSizer(1, 2, 0, 0)
        grid_sizer_52 = wx.FlexGridSizer(1, 2, 0, 0)
        grid_sizer_50 = wx.FlexGridSizer(1, 2, 0, 0)
        grid_sizer_47 = wx.GridSizer(1, 2, 0, 20)
        grid_sizer_49 = wx.FlexGridSizer(1, 3, 0, 0)
        grid_sizer_48 = wx.FlexGridSizer(1, 2, 0, 0)
        sizer_5 = wx.StaticBoxSizer(self.sizer_5_staticbox, wx.HORIZONTAL)
        grid_sizer_31 = wx.FlexGridSizer(5, 1, 3, 0)
        grid_sizer_41 = wx.GridSizer(3, 1, 1, 0)
        grid_sizer_45 = wx.FlexGridSizer(1, 2, 0, 0)
        grid_sizer_44 = wx.FlexGridSizer(1, 2, 0, 0)
        grid_sizer_43 = wx.FlexGridSizer(1, 2, 0, 0)
        grid_sizer_42 = wx.FlexGridSizer(1, 2, 0, 0)
        grid_sizer_37 = wx.GridSizer(1, 3, 0, 2)
        grid_sizer_40 = wx.FlexGridSizer(1, 3, 0, 0)
        grid_sizer_39 = wx.FlexGridSizer(1, 3, 0, 0)
        grid_sizer_38 = wx.FlexGridSizer(1, 3, 0, 0)
        grid_sizer_36 = wx.FlexGridSizer(1, 2, 0, 0)
        grid_sizer_33 = wx.GridSizer(1, 2, 0, 20)
        grid_sizer_35 = wx.FlexGridSizer(1, 2, 0, 0)
        grid_sizer_34 = wx.FlexGridSizer(1, 2, 0, 0)
        sizer_2 = wx.StaticBoxSizer(self.sizer_2_staticbox, wx.HORIZONTAL)
        grid_sizer_3 = wx.GridSizer(2, 1, 3, 0)
        grid_sizer_10 = wx.GridSizer(1, 2, 0, 3)
        grid_sizer_21 = wx.FlexGridSizer(1, 3, 0, 0)
        grid_sizer_20 = wx.FlexGridSizer(1, 3, 0, 0)
        grid_sizer_5 = wx.GridSizer(1, 3, 0, 3)
        grid_sizer_19 = wx.FlexGridSizer(1, 2, 0, 0)
        grid_sizer_18 = wx.FlexGridSizer(1, 2, 0, 0)
        grid_sizer_17 = wx.FlexGridSizer(1, 2, 0, 0)
        sizer_6 = wx.StaticBoxSizer(self.sizer_6_staticbox, wx.HORIZONTAL)
        grid_sizer_1 = wx.GridSizer(1, 3, 6, 6)
        grid_sizer_16 = wx.FlexGridSizer(1, 2, 0, 0)
        grid_sizer_9 = wx.FlexGridSizer(1, 2, 0, 0)
        grid_sizer_7 = wx.FlexGridSizer(1, 2, 0, 0)
        grid_sizer_7.Add(self.khdm_label, 0, wx.ALIGN_CENTER_VERTICAL, 0)
        grid_sizer_7.Add(self.khdm_ctrl, 0, wx.ALIGN_CENTER_VERTICAL, 0)
        grid_sizer_1.Add(grid_sizer_7, 1, wx.EXPAND, 0)
        grid_sizer_9.Add(self.khmc_label, 0, wx.ALIGN_CENTER_VERTICAL, 0)
        grid_sizer_9.Add(self.khmc_ctrl, 0, wx.ALIGN_CENTER_VERTICAL, 0)
        grid_sizer_1.Add(grid_sizer_9, 1, wx.EXPAND, 0)
        grid_sizer_16.Add(self.yewy_label, 0, wx.ALIGN_CENTER_VERTICAL, 0)
        grid_sizer_16.Add(self.yewy_ctrl, 0, wx.ALIGN_CENTER_VERTICAL, 0)
        grid_sizer_1.Add(grid_sizer_16, 1, wx.EXPAND, 0)
        sizer_6.Add(grid_sizer_1, 1, wx.EXPAND, 0)
        sizer_1.Add(sizer_6, 0, wx.EXPAND, 0)
        grid_sizer_17.Add(self.bjrq_label, 0, wx.ALIGN_CENTER_VERTICAL, 0)
        grid_sizer_17.Add(self.bjrq_datectrl, 0, wx.ALIGN_CENTER_VERTICAL, 0)
        grid_sizer_5.Add(grid_sizer_17, 1, wx.EXPAND, 0)
        grid_sizer_18.Add(self.bjyx_label, 0, wx.ALIGN_CENTER_VERTICAL, 0)
        grid_sizer_18.Add(self.bjyx_datectrl, 0, wx.ALIGN_CENTER_VERTICAL, 0)
        grid_sizer_5.Add(grid_sizer_18, 1, wx.EXPAND, 0)
        grid_sizer_19.Add(self.ddsl_label, 0, wx.ALIGN_CENTER_VERTICAL, 0)
        grid_sizer_19.Add(self.ddsl_ctrl, 0, wx.ALIGN_CENTER_VERTICAL, 0)
        grid_sizer_5.Add(grid_sizer_19, 1, wx.EXPAND, 0)
        grid_sizer_3.Add(grid_sizer_5, 1, wx.EXPAND, 0)
        grid_sizer_20.Add(self.ddjs_label, 0, wx.ALIGN_CENTER_VERTICAL, 0)
        grid_sizer_20.Add(self.ddjs_datectrl, 0, wx.ALIGN_CENTER_VERTICAL, 0)
        grid_sizer_20.Add(self.ddjs_timectrl, 0, wx.ALIGN_CENTER_VERTICAL, 0)
        grid_sizer_10.Add(grid_sizer_20, 1, wx.EXPAND, 0)
        grid_sizer_21.Add(self.ddff_label, 0, wx.ALIGN_CENTER_VERTICAL, 0)
        grid_sizer_21.Add(self.ddff_datectrl, 0, wx.ALIGN_CENTER_VERTICAL, 0)
        grid_sizer_21.Add(self.ddff_timectrl, 0, wx.ALIGN_CENTER_VERTICAL, 0)
        grid_sizer_10.Add(grid_sizer_21, 1, wx.EXPAND, 0)
        grid_sizer_3.Add(grid_sizer_10, 1, wx.EXPAND, 0)
        sizer_2.Add(grid_sizer_3, 1, wx.EXPAND, 0)
        sizer_1.Add(sizer_2, 0, wx.EXPAND, 0)
        grid_sizer_34.Add(self.hth_label, 0, wx.ALIGN_CENTER_VERTICAL, 0)
        grid_sizer_34.Add(self.hth_ctrl, 0, wx.ALIGN_CENTER_VERTICAL, 0)
        grid_sizer_33.Add(grid_sizer_34, 1, wx.EXPAND, 0)
        grid_sizer_35.Add(self.ycsl_label, 0, wx.ALIGN_CENTER_VERTICAL, 0)
        grid_sizer_35.Add(self.ycsl_ctrl, 0, wx.ALIGN_CENTER_VERTICAL, 0)
        grid_sizer_33.Add(grid_sizer_35, 1, wx.EXPAND, 0)
        grid_sizer_31.Add(grid_sizer_33, 1, wx.EXPAND, 0)
        grid_sizer_36.Add(self.ycyy_label, 0, wx.ALIGN_CENTER_VERTICAL, 0)
        grid_sizer_36.Add(self.ycyy_ctrl, 0, wx.ALIGN_CENTER_VERTICAL, 0)
        grid_sizer_31.Add(grid_sizer_36, 1, wx.EXPAND, 0)
        grid_sizer_38.Add(self.czsj_label, 0, wx.ALIGN_CENTER_VERTICAL, 0)
        grid_sizer_38.Add(self.czsj_datectrl, 0, wx.ALIGN_CENTER_VERTICAL, 0)
        grid_sizer_38.Add(self.czsj_timectrl, 0, wx.ALIGN_CENTER_VERTICAL, 0)
        grid_sizer_37.Add(grid_sizer_38, 1, wx.EXPAND, 0)
        grid_sizer_39.Add(self.xgsj_label, 0, wx.ALIGN_CENTER_VERTICAL, 0)
        grid_sizer_39.Add(self.xgsj_datectrl, 0, wx.ALIGN_CENTER_VERTICAL, 0)
        grid_sizer_39.Add(self.xgsj_timectrl, 0, wx.ALIGN_CENTER_VERTICAL, 0)
        grid_sizer_37.Add(grid_sizer_39, 1, wx.EXPAND, 0)
        grid_sizer_40.Add(self.hcsj_label, 0, wx.ALIGN_CENTER_VERTICAL, 0)
        grid_sizer_40.Add(self.hcsj_datectrl, 0, wx.ALIGN_CENTER_VERTICAL, 0)
        grid_sizer_40.Add(self.hcsj_timectrl, 0, wx.ALIGN_CENTER_VERTICAL, 0)
        grid_sizer_37.Add(grid_sizer_40, 1, wx.EXPAND, 0)
        grid_sizer_31.Add(grid_sizer_37, 1, wx.EXPAND, 0)
        grid_sizer_42.Add(self.xgyy_label, 0, 0, 0)
        grid_sizer_42.Add(self.xgyy_ctrl, 0, wx.ALIGN_CENTER_VERTICAL, 0)
        grid_sizer_31.Add(grid_sizer_42, 1, wx.EXPAND, 0)
        grid_sizer_43.Add(self.half_label, 0, wx.ALIGN_CENTER_VERTICAL, 0)
        grid_sizer_43.Add(self.half_ctrl, 0, wx.ALIGN_CENTER_VERTICAL, 0)
        grid_sizer_41.Add(grid_sizer_43, 1, wx.EXPAND, 0)
        grid_sizer_44.Add(self.two_label, 0, wx.ALIGN_CENTER_VERTICAL, 0)
        grid_sizer_44.Add(self.two_ctrl, 0, wx.ALIGN_CENTER_VERTICAL, 0)
        grid_sizer_41.Add(grid_sizer_44, 1, wx.EXPAND, 0)
        grid_sizer_45.Add(self.day_label, 0, wx.ALIGN_CENTER_VERTICAL, 0)
        grid_sizer_45.Add(self.day_ctrl, 0, wx.ALIGN_CENTER_VERTICAL, 0)
        grid_sizer_41.Add(grid_sizer_45, 1, wx.EXPAND, 0)
        grid_sizer_31.Add(grid_sizer_41, 1, wx.EXPAND, 0)
        sizer_5.Add(grid_sizer_31, 1, wx.EXPAND, 0)
        sizer_1.Add(sizer_5, 0, wx.EXPAND, 0)
        grid_sizer_48.Add(self.tcry_label, 0, wx.ALIGN_CENTER_VERTICAL, 0)
        grid_sizer_48.Add(self.tcry_ctrl, 0, wx.ALIGN_CENTER_VERTICAL, 0)
        grid_sizer_47.Add(grid_sizer_48, 1, wx.EXPAND, 0)
        grid_sizer_49.Add(self.tcff_label, 0, wx.ALIGN_CENTER_VERTICAL, 0)
        grid_sizer_49.Add(self.tcff_datectrl, 0, wx.ALIGN_CENTER_VERTICAL, 0)
        grid_sizer_49.Add(self.tcff_timectrl, 0, wx.ALIGN_CENTER_VERTICAL, 0)
        grid_sizer_47.Add(grid_sizer_49, 1, wx.EXPAND, 0)
        grid_sizer_46.Add(grid_sizer_47, 1, wx.EXPAND, 0)
        grid_sizer_50.Add(self.noback_label, 0, wx.ALIGN_CENTER_VERTICAL, 0)
        grid_sizer_50.Add(self.noback_ctrl, 0, wx.ALIGN_CENTER_VERTICAL, 0)
        grid_sizer_46.Add(grid_sizer_50, 1, wx.EXPAND, 0)
        grid_sizer_52.Add(self.zzzq_label, 0, wx.ALIGN_CENTER_VERTICAL, 0)
        grid_sizer_52.Add(self.zzzq_ctrl, 0, wx.ALIGN_CENTER_VERTICAL, 0)
        grid_sizer_51.Add(grid_sizer_52, 1, wx.EXPAND, 0)
        grid_sizer_53.Add(self.tczq_label, 0, wx.ALIGN_CENTER_VERTICAL, 0)
        grid_sizer_53.Add(self.tczq_ctrl, 0, wx.ALIGN_CENTER_VERTICAL, 0)
        grid_sizer_51.Add(grid_sizer_53, 1, wx.EXPAND, 0)
        grid_sizer_46.Add(grid_sizer_51, 1, wx.EXPAND, 0)
        grid_sizer_54.Add(self.bz_label, 0, 0, 0)
        grid_sizer_54.Add(self.bz_ctrl, 0, wx.ALIGN_CENTER_VERTICAL, 0)
        grid_sizer_46.Add(grid_sizer_54, 1, wx.EXPAND, 0)
        sizer_7.Add(grid_sizer_46, 1, wx.EXPAND, 0)
        sizer_1.Add(sizer_7, 0, wx.EXPAND, 0)
        grid_sizer_2.Add(self.save_button, 0, wx.ALIGN_CENTER_HORIZONTAL|wx.ALIGN_CENTER_VERTICAL, 0)
        grid_sizer_2.Add(self.cancel_button, 0, wx.ALIGN_CENTER_HORIZONTAL|wx.ALIGN_CENTER_VERTICAL, 0)
        sizer_3.Add(grid_sizer_2, 1, wx.EXPAND, 0)
        sizer_1.Add(sizer_3, 0, wx.ALL|wx.EXPAND, 10)
        self.SetSizer(sizer_1)
        sizer_1.Fit(self)
        self.Layout()


#查询客户名称和销售员代码的线程------------------------------------------
class QueryKHXS(threading.Thread):
    
    def __init__(self,value,window):
        threading.Thread.__init__(self)
        self.value=value
        self.window=window

          
    def run(self):
        try:
            conn,cur=DBConnection()
            QueryString="SELECT DATA0010.ABBR_NAME,DATA0009.REP_CODE FROM DATA0010 INNER JOIN DATA0009 ON DATA0010.SALES_REP_NUMBER = DATA0009.RKEY WHERE DATA0010.CUST_CODE = %s" %(self.value)
            cur.execute(QueryString)
            data=cur.fetchone()
            if data!=None:
                khmc,yewy=data[0],data[1]
                self.window.khmc_ctrl.SetValue(khmc)
                self.window.yewy_ctrl.SetValue(yewy)
            else:
                self.window.khmc_ctrl.SetValue("")
                self.window.yewy_ctrl.SetValue("")
                wx.MessageBox(u"查询不到'%s'的相关信息，检查客户代码是否正确!"%self.value,"Error")
                
            cur.close()
            conn.close()
        except:
            wx.MessageBox(u"数据库连接错误,无法获得客户名称和业务员代码！","Error")
            
            #if self.value!="":
                #QueryString="SELECT DATA0010.ABBR_NAME,DATA0009.REP_CODE FROM DATA0010 INNER JOIN DATA0009 ON DATA0010.SALES_REP_NUMBER = DATA0009.RKEY WHERE DATA0010.CUST_CODE = %s" %(self.value)
                #cur.execute(QueryString)
                #data=cur.fetchone()
                #if data!=None:
                    #khmc,yewy=data[0],data[1]
                    #self.window.khmc_ctrl.SetValue(khmc)
                    #self.window.yewy_ctrl.SetValue(yewy)
                #else:
                    #self.window.khmc_ctrl.SetValue("")
                    #self.window.yewy_ctrl.SetValue("")
                    #wx.MessageBox(u"查询不到'%s'的相关信息，检查客户代码是否正确!"%self.value,"Error")
                #cur.close()
                #conn.close()
            #else:
                #pass
        #except:
            #wx.MessageBox(u"数据库连接错误,无法获得客户名称和业务员代码！","Error")
#------------------------------------------------------------------------------------

if __name__ == "__main__":
    app = wx.PySimpleApp(0)
    wx.InitAllImageHandlers()
    edit_dialog = EditDialog(None, -1, "","")
    app.SetTopWindow(edit_dialog)
    edit_dialog.Show()
    app.MainLoop()
